package cn.edu.scau.cmi.lishuoxin.client.experiment3;

import cn.edu.scau.cmi.lishuoxin.interProgramming.experiment3.factory.SimpleFactory;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;

public class FactoryClient2 extends Pane {
	
	private Button control = new Button("显示保险信息");
	private ComboBox<String> insuranceBox = new ComboBox<>();
	private Image photo = new Image("file:D:\\java_work\\201627010409李烁新\\pic\\1422.jpg");
	private ImageView imageView = new ImageView();
	private SimpleFactory simpleFactory = new SimpleFactory();
	private Label explain = new Label("详细信息显示.....");
	private Label name = new Label("姓名：     李烁新         ");
	private Label number = new Label("学号： 201627010409 ");
	private Label insuranceType = new Label("请选择保险类型：");
	private String[] types = { "CarBroken", "DriverHurt", "PersonHurt", "ManyAccident" };

	public FactoryClient2() {
        this.addImage();
        this.addExplain();
        this.addNameAndNum();
        this.addTypes();
        this.addButton();
	}

	private void addImage() {
		imageView.setImage(photo);
		this.getChildren().add(imageView);
		imageView.setFitHeight(300);
		imageView.setFitWidth(300);
		imageView.setLayoutX(20);
		imageView.setLayoutY(20);
	}

	private void addNameAndNum() {
		this.getChildren().add(number);
		number.setLayoutX(350);
		number.setLayoutY(30);
		this.getChildren().add(name);
		name.setLayoutX(550);
		name.setLayoutY(30);
	}

	private void addTypes() {
		this.getChildren().add(insuranceType);
		insuranceType.setLayoutX(350);
		insuranceType.setLayoutY(100);
		ObservableList<String> items = FXCollections.observableArrayList(types);
		insuranceBox.getItems().addAll(items);
		this.getChildren().add(insuranceBox);
		insuranceBox.setLayoutX(500);
		insuranceBox.setLayoutY(100);
	}

	private void addExplain() {
		this.getChildren().add(explain);
		explain.setLayoutX(350);
		explain.setLayoutY(300);
	}

	private void addButton() {
		this.getChildren().add(control);
		control.setLayoutX(350);
		control.setLayoutY(200);
		control.setOnAction(e->{
			actionForSimple();
		});
	}
	
	private void actionForSimple() {
		String msg = simpleFactory.getInstance(insuranceBox.getValue()).toString();
		explain.setText(msg);
	}
}
